package org.goodsl.mdd.paint;

/**
 * Created with IntelliJ IDEA.
 * User: simonxiao
 * Date: 12-11-25
 * Time: 下午12:32
 * Copyright goodsl.org 2012~2020
 */

import org.goodsl.mdd.Box;
import org.goodsl.mdd.BoxBuilder;
import org.goodsl.mdd.BoxInfo;
import org.goodsl.mdd.Seg;

import java.util.HashMap;

/**
 * 协助完成Box的数据填充过程
 */
public class BoxPainter {

    private Box _box;
    private BoxInfo _boxInfo;

    public Box getBox(){
        return _box;
    }

    public BoxPainter(Class<? extends Box> boxClass,
                      HashMap<String,Object> values)throws Exception{
        this(BoxBuilder.makeBox(boxClass),values);

    }

    public BoxPainter(Class<? extends Box> boxClass)throws Exception{
         this(BoxBuilder.makeBox( boxClass),null);
    }

    public BoxPainter(Box box) {
       this(box,null);
    }

    public BoxPainter(Box box,
                      HashMap<String,Object> values) {
        this._box = box;
        this._boxInfo = box.getBoxInfo();

        for(String segName : values.keySet()){
            Seg seg = box.getSeg(segName);
            if(seg!=null){
                try{
                    seg.setValue(values.get(segName));
                }catch (Exception e){}
            }
        }
    }


    public boolean  isDone(){
       return !(_box ==null || !_box.verify().getIsValid());
    }

    public BoxRequire checkRequire(){

        return null;
    }
}
